package com.walkthecow.justdraw;

import java.io.File;
import java.io.FileInputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;

public class LoadBitmap {
	/*	
	public boolean isSdWritable() {

		boolean mExternalStorageWriteable = false;
		
		String state = Environment.getExternalStorageState();

		if (Environment.MEDIA_MOUNTED.equals(state)) {
			// We can read and write the media
			mExternalStorageWriteable = true;
			// Get the File path.
		} else {
			// Something else is wrong. It may be one of many other states, but all we need
			//  to know is we can neither read nor write
			mExternalStorageWriteable = false;
		}
		return mExternalStorageWriteable;

	}

	public boolean isSdReadable() {

		boolean mExternalStorageAvailable = false;

		String state = Environment.getExternalStorageState();

		if (Environment.MEDIA_MOUNTED.equals(state)) {
			// We can read and write the media
			mExternalStorageAvailable = true;
		} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
			// We can only read the media
			mExternalStorageAvailable = true;
		} else {
			// Something else is wrong. It may be one of many other states, but all we need
			//  to know is we can neither read nor write
			mExternalStorageAvailable = false;
		}
		return mExternalStorageAvailable;

	}
	
	public Bitmap getPicture(String filename) {

		String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + APP_PATH_SD_CARD + APP_THUMBNAIL_PATH_SD_CARD;
		Bitmap thumbnail = null;

		// Look for the file on the external storage
		try {
			if (isSdAvailable() == true) {
				thumbnail = BitmapFactory.decodeFile(fullPath + "/" + filename);
			}
		} catch (Exception e) {
			Log.e("getThumbnail() on external storage", e.getMessage());
		}

		// If no file on external storage, look in internal storage
		if (thumbnail == null) {
			try {
				File filePath = getFileStreamPath(filename);
				FileInputStream fi = new FileInputStream(filePath);
				thumbnail = BitmapFactory.decodeStream(fi);
			} catch (Exception ex) {
				Log.e("getThumbnail() on internal storage", ex.getMessage());
			}
		}
		return thumbnail;
	}
	
	public void loadImage(){
		Uri selectedImageUri = data.getData();
		selectedImagePath = getPath(selectedImageUri);
		Uri uri = Uri.parse(selectedImagePath);
		uploadimage.setImageURI(uri);
		Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
		
		
		startActivityForResult(new Intent(Intent.ACTION_PICK,
		         android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
		myIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
		
	}
	*/
}
